require 'set'

module StarFrame
  class Sprite
    attr_reader :collection
    
    def vanish
      if @collection
        @collection.delete self
        @collection = nil
      end
      self
    end
    
    def collection= collection # :nodoc:
      @collection.delete self if @collection
      @collection = collection
    end
    
    class Collection < Array
      def << sprite
        sprite.collection = self
        super
      end
      
      def call
        each{ |sprite| sprite.call }
      end
      
      def render_to texture
        each{ |sprite| sprite.render_to texture }
      end
    end
  end
end
